class ParamFormat {
	constructor(arr) {
		arr=arr||process.argv.slice(2);
		this.param = {};
		let insert = false;
		let lastKey = null;
		for (let i = 0; i < arr.length; i++) {
			let str = arr[i];
			if (str.startsWith("-")) {
				insert = true;
				lastKey = str;
			} else if (insert) {
				this.param[lastKey] = str;
			}
		}
	}
	//获得值
	getValueAsString(key){
		if (key) {
			return this.param[key];
		}
	}
	getValue(key,def=null){
		let res=this.getValueAsString(key);
		res=res==null?def:res;
		if (res==null) {
			throw new Error(`请补全:${key}`);
		}
		return res;
	}
}
module.exports = {
	ParamFormat
};
